<template>
  <div class="leader-set">
    <template v-if="leader != null">
      {{ leader }} <el-button size="mini" type="text" @click="handleLeaderSet">修改总指挥</el-button>
    </template>
    <template v-else>
      <el-button size="mini" type="text" @click="handleLeaderSet">设置总指挥</el-button>
    </template>
    <staff-choose-dialog ref="staffChooseDialog" :muilt="false" @Unitpersonnel="onStaffChoose" />
  </div>
</template>
<script>
import StaffChooseDialog from "@/views/components/staffChooseDialog/index.vue";
import { planLeaderSet } from "@/api/response/handle.js";
export default {
  name: "LeaderSet",
  components: {
    StaffChooseDialog
  },
  props: {
    leader: {
      type: String,
      default: null
    },
    id: {
      type: Number,
      default: 0
    }
  },
  methods: {
    handleLeaderSet() {
      this.$refs.staffChooseDialog.showDialog("选择总指挥");
    },
    onStaffChoose(deptId, userId, user, dept) {
      planLeaderSet({ handleInfoId: this.id, userId: userId, userName: user.userName }).then(res => {
        if (res.code == 200) {
          // 提交成功
          this.$modal.msgSuccess("总指挥设置成功");
          this.$emit("handleOk")
        } else {
          // 提交失败
          this.$modal.msgError("总指挥设置失败");
        }
      });
    },
  }
}
</script>
<style lang="scss" scoped></style>